package sellcar;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import java.sql.*;


/**
 *
 * @author Fabio Valezuela
 */
public class Cadastro_Veiculo extends javax.swing.JFrame {
    
        private Connection connection;


    /**
     * Creates new form CadastrodeCarros
     */
    public Cadastro_Veiculo() {
        
        
        initComponents();
        mostrar();        
        this.setLocationRelativeTo(null);
        getRootPane().setDefaultButton(BtSalvar);
        this.connection = new ConnectionFactory().getConnection();
        try {
            pesquisa();
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Veiculo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GrOrigem = new javax.swing.ButtonGroup();
        GrEstado = new javax.swing.ButtonGroup();
        Titulo = new javax.swing.JLabel();
        RdNac = new javax.swing.JRadioButton();
        RdImp = new javax.swing.JRadioButton();
        RdNovo = new javax.swing.JRadioButton();
        RDUsado = new javax.swing.JRadioButton();
        CombMarca = new javax.swing.JComboBox();
        CombModelo = new javax.swing.JComboBox();
        CombCombust = new javax.swing.JComboBox();
        CombCambio = new javax.swing.JComboBox();
        CombPortas = new javax.swing.JComboBox();
        TxTFab = new javax.swing.JTextField();
        TxtKm = new javax.swing.JTextField();
        TxtCor = new javax.swing.JTextField();
        ChArCond = new javax.swing.JCheckBox();
        ChAirBag = new javax.swing.JCheckBox();
        ChAlarme = new javax.swing.JCheckBox();
        ChCd = new javax.swing.JCheckBox();
        ChDirHi = new javax.swing.JCheckBox();
        ChAbs = new javax.swing.JCheckBox();
        ChTravas = new javax.swing.JCheckBox();
        ChVidros = new javax.swing.JCheckBox();
        ChDvd = new javax.swing.JCheckBox();
        ChTeto = new javax.swing.JCheckBox();
        ChSensor = new javax.swing.JCheckBox();
        ChBanco = new javax.swing.JCheckBox();
        ChCompu = new javax.swing.JCheckBox();
        ChLimpador = new javax.swing.JCheckBox();
        ChDesen = new javax.swing.JCheckBox();
        TituloOp = new javax.swing.JLabel();
        TxtValorCompra = new javax.swing.JLabel();
        Fabric = new javax.swing.JLabel();
        Placa = new javax.swing.JLabel();
        Km = new javax.swing.JLabel();
        Cor = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        BtSalvar = new javax.swing.JButton();
        BtLimpar = new javax.swing.JButton();
        BtVoltar = new javax.swing.JButton();
        TxtValorComp = new sellcar.JNumberFormatField();
        jPanel1 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        BtPesquisar = new javax.swing.JButton();
        TxtPlaca = new javax.swing.JFormattedTextField();
        jSeparator3 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro Carros");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        Titulo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        Titulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Titulo.setText("CADASTRO DE VEÍCULOS");

        GrOrigem.add(RdNac);
        RdNac.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RdNac.setText("Nacional");

        GrOrigem.add(RdImp);
        RdImp.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RdImp.setText("Importado");

        GrEstado.add(RdNovo);
        RdNovo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RdNovo.setText("Novo");

        GrEstado.add(RDUsado);
        RDUsado.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RDUsado.setText("Usado");

        CombMarca.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CombMarca.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Marca", "Chevrolet", "Fiat", "Ford", "Peugeot", "Renault", "Volkswagen" }));

        CombModelo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CombModelo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Modelo", "Corsa", "Uno", "Focus", "206", "Clio", "Gol" }));

        CombCombust.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CombCombust.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Combustível", "Álcool", "Diesel", "Flex", "Gás Natural", "Gasolina", " " }));

        CombCambio.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CombCambio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Câmbio", "Automatico", "Automatico Sequência", "CVT", "Manual", "Semi-Automatico" }));

        CombPortas.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CombPortas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Portas", "2", "3", "4" }));

        TxTFab.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxTFab.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        TxtKm.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        TxtCor.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        ChArCond.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChArCond.setText("Ar Condicionado");

        ChAirBag.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChAirBag.setText("Air Bag");

        ChAlarme.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChAlarme.setText("Alarme");

        ChCd.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChCd.setText("CD Player");

        ChDirHi.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChDirHi.setText("Direção Hidraulica");

        ChAbs.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChAbs.setText("Freio ABS");

        ChTravas.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChTravas.setText("Travas Eletricas");

        ChVidros.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChVidros.setText("Vidros Eletricos");

        ChDvd.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChDvd.setText("DVD Player");

        ChTeto.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChTeto.setText("Teto Solar");

        ChSensor.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChSensor.setText("Sensor de Estacionamento");

        ChBanco.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChBanco.setText("Banco de Couro");

        ChCompu.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChCompu.setText("Computador de Bordo");

        ChLimpador.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChLimpador.setText("Limpador Traseiro");

        ChDesen.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ChDesen.setText("Desembaçador Traseiro");

        TituloOp.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TituloOp.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TituloOp.setText("Opcionais");

        TxtValorCompra.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TxtValorCompra.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TxtValorCompra.setText("Valor de Compra");

        Fabric.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Fabric.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Fabric.setText("Ano de Fab.");

        Placa.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Placa.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Placa.setText("Placa");

        Km.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Km.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Km.setText("Kilometragem");

        Cor.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Cor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Cor.setText("Cor");

        BtSalvar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/document_save_as.png"))); // NOI18N
        BtSalvar.setMnemonic('S');
        BtSalvar.setText("Salvar");
        BtSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtSalvarActionPerformed(evt);
            }
        });

        BtLimpar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/cancel.png"))); // NOI18N
        BtLimpar.setMnemonic('L');
        BtLimpar.setText("Limpar");
        BtLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtLimparActionPerformed(evt);
            }
        });

        BtVoltar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/arrow_left.png"))); // NOI18N
        BtVoltar.setText("Voltar");
        BtVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtVoltarActionPerformed(evt);
            }
        });

        TxtValorComp.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/delete.png"))); // NOI18N
        jButton2.setText("Excluir");

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/resultset_next.png"))); // NOI18N
        jButton3.setText("Proximo");

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/pencil.png"))); // NOI18N
        jButton5.setText("Alterar");

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/resultset_previous.png"))); // NOI18N
        jButton4.setText("Anterior");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jButton4)))
                .addGap(0, 17, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        BtPesquisar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BtPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sellcar/Icones/find.png"))); // NOI18N
        BtPesquisar.setText("Pesquisa");
        BtPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtPesquisarActionPerformed(evt);
            }
        });

        try {
            TxtPlaca.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("AAA-AAAA")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        TxtPlaca.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        TxtPlaca.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(TituloOp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(66, 66, 66))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(CombMarca, 0, 114, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(CombModelo, 0, 90, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(CombCombust, 0, 114, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(CombCambio, 0, 167, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(CombPortas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(55, 55, 55)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(BtSalvar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(BtLimpar))
                                    .addComponent(BtPesquisar))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(BtVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator3))
                        .addGap(31, 31, 31))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(87, 87, 87)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ChAirBag)
                            .addComponent(ChAlarme)
                            .addComponent(ChCd)
                            .addComponent(ChDvd)
                            .addComponent(ChArCond))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ChTeto)
                            .addComponent(ChDirHi)
                            .addComponent(ChAbs)
                            .addComponent(ChVidros)
                            .addComponent(ChTravas))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ChCompu)
                            .addComponent(ChSensor)
                            .addComponent(ChBanco)
                            .addComponent(ChDesen)
                            .addComponent(ChLimpador))
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(182, 182, 182)
                        .addComponent(Titulo, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(TxtValorCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TxtValorComp, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(122, 122, 122)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TxTFab)
                            .addComponent(Fabric, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TxtPlaca)
                            .addComponent(Placa, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TxtKm, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Km, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TxtCor, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Cor, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(147, 147, 147)
                        .addComponent(RdNac)
                        .addGap(18, 18, 18)
                        .addComponent(RdImp)
                        .addGap(37, 37, 37)
                        .addComponent(RdNovo)
                        .addGap(18, 18, 18)
                        .addComponent(RDUsado)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Titulo)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RdNac)
                    .addComponent(RdImp)
                    .addComponent(RdNovo)
                    .addComponent(RDUsado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CombMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CombModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CombCombust, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CombCambio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CombPortas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Fabric)
                    .addComponent(Placa)
                    .addComponent(Km)
                    .addComponent(Cor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxTFab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtKm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TituloOp)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ChSensor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ChBanco)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ChLimpador))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ChAirBag)
                            .addComponent(ChDirHi))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ChAlarme)
                            .addComponent(ChAbs))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ChTravas)
                            .addComponent(ChArCond))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ChDesen)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ChCompu))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ChCd)
                            .addComponent(ChVidros))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ChDvd)
                            .addComponent(ChTeto))))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtValorCompra)
                    .addComponent(TxtValorComp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(BtPesquisar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtSalvar)
                            .addComponent(BtLimpar)
                            .addComponent(BtVoltar))))
                .addContainerGap())
        );

        ChAirBag.getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BtVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtVoltarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_BtVoltarActionPerformed

    private void BtSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtSalvarActionPerformed
        // TODO add your handling code here:
        Veiculo veiculo = new Veiculo();
        
    veiculo.setEstado(escolheEstado());
    veiculo.setOrigem(escolheOrigem());
    veiculo.setMarca(CombMarca.getSelectedIndex());
    veiculo.setModelo(CombModelo.getSelectedIndex());
    veiculo.setFab(TxTFab.getText());
    veiculo.setPlaca(TxtPlaca.getText());
    veiculo.setKm(TxtKm.getText());
    veiculo.setCor(TxtCor.getText());
    veiculo.setAirBag(ChAirBag.isSelected());
    veiculo.setAlarme(ChAlarme.isSelected());
    veiculo.setArCond(ChArCond.isSelected());
    veiculo.setCd(ChCd.isSelected());
    veiculo.setDvd(ChDvd.isSelected());
    veiculo.setDirHi(ChDirHi.isSelected()); 
    veiculo.setAbs(ChAbs.isSelected());
    veiculo.setTravas(ChTravas.isSelected());
    veiculo.setVidros(ChVidros.isSelected());
    veiculo.setValorComp(TxtValorComp.getValue());
    veiculo.setTeto(ChTeto.isSelected());
    veiculo.setSensor(ChSensor.isSelected());
    veiculo.setBanco(ChBanco.isSelected());
    veiculo.setLimpador(ChLimpador.isSelected());
    veiculo.setDesen(ChDesen.isSelected());
    veiculo.setCompu(ChCompu.isSelected());
    veiculo.setCambio(CombCambio.getSelectedIndex());
    veiculo.setCombust(CombCombust.getSelectedIndex());
    veiculo.setPortas(CombPortas.getSelectedIndex());
    
       
    Cadastro_VeiculoDAO cadastro_veiculoDAO = new Cadastro_VeiculoDAO();
        cadastro_veiculoDAO.adiciona(veiculo);
        JOptionPane.showMessageDialog(null,"Veiculo Cadastrado com Sucesso");
    }//GEN-LAST:event_BtSalvarActionPerformed

    private void BtLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtLimparActionPerformed
        // Limpar todos os campos digitados
        
        limparTodosCampos(rootPane);
        
        ChAirBag.setSelected(false);
        ChAlarme.setSelected(false);
        ChArCond.setSelected(false);
        ChBanco.setSelected(false);
        ChCd.setSelected(false);
        ChCompu.setSelected(false);
        ChDesen.setSelected(false);
        ChDirHi.setSelected(false);
        ChDvd.setSelected(false);
        ChLimpador.setSelected(false);
        ChSensor.setSelected(false);
        ChTeto.setSelected(false);
        ChTravas.setSelected(false);
        ChVidros.setSelected(false);
        ChAbs.setSelected(false);
        CombCambio.setSelectedIndex(0);
        CombCombust.setSelectedIndex(0);
        CombMarca.setSelectedIndex(0);
        CombModelo.setSelectedIndex(0);
        CombPortas.setSelectedIndex(0);
       
                
        
                
       //requestFocus(); // quando limpar vai pra ele
    }//GEN-LAST:event_BtLimparActionPerformed

    private void BtPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtPesquisarActionPerformed
        // TODO add your handling code here:
                try {
            rsMostrar.first();
            
            //RdNac
            //RdImp
            //RdNovo
            //RDUsado
            
            TxTFab.setText(rsMostrar.getString("desc_modelo_ano"));
            TxtPlaca.setText(rsMostrar.getString("placa"));
            TxtKm.setText(rsMostrar.getString("kilometragem"));
            TxtCor.setText(rsMostrar.getString("cor"));
            TxtValorComp.setText(rsMostrar.getString("valor_compra"));
            
            
            

        } catch (Exception ex) {
            JOptionPane.showInternalMessageDialog(null, "Erro:\n" + ex);
        }


    }//GEN-LAST:event_BtPesquisarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Veiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Veiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Veiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Cadastro_Veiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Cadastro_Veiculo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtLimpar;
    private javax.swing.JButton BtPesquisar;
    private javax.swing.JButton BtSalvar;
    private javax.swing.JButton BtVoltar;
    private javax.swing.JCheckBox ChAbs;
    private javax.swing.JCheckBox ChAirBag;
    private javax.swing.JCheckBox ChAlarme;
    private javax.swing.JCheckBox ChArCond;
    private javax.swing.JCheckBox ChBanco;
    private javax.swing.JCheckBox ChCd;
    private javax.swing.JCheckBox ChCompu;
    private javax.swing.JCheckBox ChDesen;
    private javax.swing.JCheckBox ChDirHi;
    private javax.swing.JCheckBox ChDvd;
    private javax.swing.JCheckBox ChLimpador;
    private javax.swing.JCheckBox ChSensor;
    private javax.swing.JCheckBox ChTeto;
    private javax.swing.JCheckBox ChTravas;
    private javax.swing.JCheckBox ChVidros;
    private javax.swing.JComboBox CombCambio;
    private javax.swing.JComboBox CombCombust;
    private javax.swing.JComboBox CombMarca;
    private javax.swing.JComboBox CombModelo;
    private javax.swing.JComboBox CombPortas;
    private javax.swing.JLabel Cor;
    private javax.swing.JLabel Fabric;
    private javax.swing.ButtonGroup GrEstado;
    private javax.swing.ButtonGroup GrOrigem;
    private javax.swing.JLabel Km;
    private javax.swing.JLabel Placa;
    private javax.swing.JRadioButton RDUsado;
    private javax.swing.JRadioButton RdImp;
    private javax.swing.JRadioButton RdNac;
    private javax.swing.JRadioButton RdNovo;
    private javax.swing.JLabel Titulo;
    private javax.swing.JLabel TituloOp;
    private javax.swing.JTextField TxTFab;
    private javax.swing.JTextField TxtCor;
    private javax.swing.JTextField TxtKm;
    private javax.swing.JFormattedTextField TxtPlaca;
    private sellcar.JNumberFormatField TxtValorComp;
    private javax.swing.JLabel TxtValorCompra;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    // End of variables declaration//GEN-END:variables
ResultSet rsMostrar = null;
    int atual = 0;
    int total = 0;

    public ResultSet pesquisa() throws SQLException {

        PreparedStatement stmt;

        String sql = "SELECT id_usuario,desc_login,senha FROM tb_usuario";
        stmt = connection.prepareStatement(sql);
        rsMostrar = stmt.executeQuery(sql);
        while (rsMostrar.next()) {
            total = total + 1;
            //JOptionPane.showMessageDialog(null, rsMostrar.getString(1));
        }
        //rsMostrar.first();
        return rsMostrar;

    }
    private void mostrar(){
        ComboboxDAO combo = new ComboboxDAO();
        ResultSet rsmarca = null;
        ResultSet rsmodelo = null;
        ResultSet rscambio = null;
        ResultSet rscombustivel = null;
        ResultSet rsporta = null;
        
        CombMarca.removeAllItems();
        CombModelo.removeAllItems();
        CombCambio.removeAllItems();
        CombCombust.removeAllItems();
        CombPortas.removeAllItems();
        
        CombMarca.addItem("MARCA");
        CombModelo.addItem("MODELO");
        CombCambio.addItem("CAMBIO");
        CombCombust.addItem("COMBUSTIVEL");
        CombPortas.addItem("PORTA");
        
        try {
            rsmarca = combo.dados_marca();
            rsmodelo = combo.dados_modelo();
            rscambio = combo.dados_cambio();
            rscombustivel = combo.dados_combustivel();
            rsporta = combo.dados_porta();
            
        } catch (SQLException ex) {
            Logger.getLogger(Cadastro_Veiculo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try{
            
            while(rsmarca.next()){
                int id = rsmarca.getInt(1);
                String nome = rsmarca.getString(2);
                CombMarca.addItem(new Marca(id,nome));
            
                
            while(rsmodelo.next()){
                int id_modelo = rsmodelo.getInt(1);
                String nome_modelo = rsmodelo.getString(3);
                CombModelo.addItem(new Marca(id_modelo,nome_modelo));
            }
                
            while(rscambio.next()){
                int id_cambio = rscambio.getInt(1);
                String nome_cambio = rscambio.getString(2);
                CombCambio.addItem(new Marca(id_cambio,nome_cambio));
            }
                
            while(rscombustivel.next()){
                int id_combustivel = rscombustivel.getInt(1);
                String nome_combustivel = rscombustivel.getString(2);
                CombCombust.addItem(new Marca(id_combustivel,nome_combustivel));
            }
                
            while(rsporta.next()){
                int id_porta = rsporta.getInt(1);
                String nome_porta = rsporta.getString(2);
                CombPortas.addItem(new Marca(id_porta,nome_porta));
            }
    }
        } catch (SQLException ex){
            Logger.getLogger(Cadastro_Veiculo.class.getName()).log(Level.SEVERE, null, ex);
        }
            
    }
    public String escolheOrigem(){
        if(RdNac.isSelected()){
            return "NACIONAL";
                    } else {
            return "IMPORTADO";
        }
    }
    public String escolheEstado(){
        if(RdNovo.isSelected()){
            return "NOVO";
                    } else {
            return "USADO";
        }
    }
    public void limparTodosCampos(Container container) {  
    Component components[] = container.getComponents();  
    for (Component component : components) {  
        if (component instanceof JFormattedTextField) {  
            JFormattedTextField field = (JFormattedTextField) component;  
            field.setValue(null);  
        } else if (component instanceof JTextField) {  
            JTextField field = (JTextField) component;  
            field.setText("");  
        } else if (component instanceof Container) {  
            limparTodosCampos((Container) component);  
        } 
    }  
}  
}
